package cn.itcast.service.impl;

import cn.itcast.dao.OrderListDao;
import cn.itcast.entity.OrderQueryPageBean;
import cn.itcast.entity.PageResult;
import cn.itcast.pojo.Order;
import cn.itcast.service.OrderListService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.UUID;

@Service
public class OrderListServiceImpl implements OrderListService {

    @Autowired
    private OrderListDao orderListDao;

    /**
     * 查询预约列表(OrderList)
     * @param currentPage
     * @param pageSize
     * @param orderQueryPageBean
     * @return
     */
    @Override
    public PageResult pageQuery(Integer currentPage, Integer pageSize, OrderQueryPageBean orderQueryPageBean) {
        PageHelper.startPage(currentPage,pageSize);
        Page<Order> page = orderListDao.selectByCondition(orderQueryPageBean);
        return new PageResult(page.getTotal(),page.getResult());
    }


    /**
     * 新增预约
     * @param order
     */
    @Override
    public void add(Order order) {
        if(order.getId() != null && order.getId().length() != 0){
            orderListDao.updateById(order);
            return;
        }
        order.setId(UUID.randomUUID().toString().replace("-",""));
        orderListDao.add(order);
    }

    /**
     * 根据预约id查询信息
     * @param id
     * @return
     */
    @Override
    public Order pageById(String id) {
        return orderListDao.pageById(id);
    }

    /**
     * 修改状态
     * @param order
     */
    @Override
    public void updataOrderStatus(Order order) {
        orderListDao.updateById(order);
    }
}
